package com.iflytek.universitymanagement.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iflytek.universitymanagement.common.Result;
import com.iflytek.universitymanagement.domain.WeakCourse;
import com.iflytek.universitymanagement.domain.WeakCourseDTO;
import com.iflytek.universitymanagement.service.WeakCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController

@RequestMapping("/weak-courses")
public class WeakCourseController {

    @Autowired
    private WeakCourseService weakCourseService;

    // 查询所有薄弱课程
    @GetMapping("/getAll")
    public List<WeakCourseDTO> getAllWeakCourses() {
        return weakCourseService.getWeakCourses();
    }

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") int pageNum,
                             @RequestParam(defaultValue = "10") int pageSize) {
        IPage<WeakCourseDTO> page = weakCourseService.selectPage(pageNum, pageSize);
        return Result.success(page);
    }

    @DeleteMapping("/delete/{id}")
    public com.iflytek.universitymanagement.config.Result deleteById(@PathVariable Integer id) {
        weakCourseService.removeById(id);
        return com.iflytek.universitymanagement.config.Result.success();
    }

    /**
     * 增加
     */

    @PostMapping("/add")
    public com.iflytek.universitymanagement.config.Result add(@RequestBody WeakCourse weakCourse) {
        weakCourseService.save(weakCourse);
        return com.iflytek.universitymanagement.config.Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public com.iflytek.universitymanagement.config.Result updateById(@RequestBody WeakCourse weakCourse) {
        weakCourseService.updateById(weakCourse);
        return com.iflytek.universitymanagement.config.Result.success();
    }

}
